var pomelo = require('pomelo');
var Conf = require('./config');

/**
 * Init app for client.
 */
var app = pomelo.createApp();
app.set('name', 'hello');

// app configuration
app.configure('production|development', 'connector', function(){
  app.set('connectorConfig',
    {
      connector : pomelo.connectors.hybridconnector,
      heartbeat: 30,
      disconnectOnTimeout: true,
      useDict : true,
      useProtobuf : true
    });
});

app.configure('production|development', 'gate', function(){
  app.set('connectorConfig',
      {
        connector : pomelo.connectors.hybridconnector,
        useProtobuf : true
      });
});

app.configure('production|development', "scene", function(){
  app.set('connectorConfig',
      {
        connector : pomelo.connectors.hybridconnector,
        useProtobuf : true,
        useDict: true
      });
});

app.configure('production|development', function() {
    app.enable('systemMonitor');
});

var conf = new Conf(app);
conf.globalChannel();
conf.statusChannel();
conf.configureRoute();
conf.initCacheDB();
conf.initDB();

// start app
app.start();

process.on('uncaughtException', function (err) {
  console.error(' Caught exception: ' + err.stack);
});
